package h0710;

import java.util.*;
import java.util.stream.Collectors;

public class TexasPoker {

    //花色 heart spade club diamond
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        Map<Integer,String> map=new HashMap<>();
        int[] nums = new int[5];
        char[] colors = new char[5];
        for (int i = 0; i < 5; i++) {
            String num = sc.next();//数字
            String color = sc.next(); //花色
            nums[i] = cards(num);
            colors[i] = color.charAt(0);
        }
        int res = getResult(nums, colors);
        System.out.println(res);
    }

    //牌的对应
    public static int cards(String num) {
        return switch (num) {
            case "J" -> 11;
            case "Q" -> 12;
            case "K" -> 13;
            case "A" -> 14;
            default -> Integer.parseInt(num);
        };
    }

    private static int getResult(int[] nums, char[] colors) {
        //判断是否同花顺
        if (isStraight(nums)&&isSameColor(colors)){
            return 1;
        }else if (isSiTiao(nums,colors)){
            return 2;
        } else if (isHuLu(nums,colors)) {
            return 3;
        }else if (isSameColor(colors)){//这里的同花和顺子没有要求那么严格，
            // 因为题目只需要输出最高优先级的牌型，只要满足较高牌型就输出就行。
            return 4;
        }else if (isStraight(nums)){
            return 5;
        }else if (isSanTiao(nums,colors)){
            return 6;
        }else {
            return 0;
        }
    }

    //是否是四条
    private static boolean isSiTiao(int[] nums, char[] colors) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        for (Integer i : map.keySet()) {
            //只要有一个出现四次，即满足条件，花色不影响。
            if (map.get(i) == 4) {
                return true;
            }
        }
        return false;
    }

    //是否是葫芦，三带一对
    private static boolean isHuLu(int[] nums, char[] colors) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        boolean a = false;
        boolean b = false;
        for (Integer i : map.keySet()) {
            //一个出现三次，一个出现两次；即满足条件，花色不影响。
            if (map.get(i) == 3) {
                a = !a;
            }
            if (map.get(i) == 2) {
                b = !b;
            }
        }
        return a && b;
    }

    //判断是否同一花色
    private static boolean isSameColor(char[] colors) {
        for (int i = 0; i < colors.length - 1; i++) {
            if (colors[i] != colors[i + 1]) {
                return false;
            }
        }
        return true;
    }

    //判断是否是顺子。注意：只有满足既是同花又是顺子才是同花顺。顺子是满足isStraight，不满足isSameColor。
    private static boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        //处理特殊情况 A 2 3 4 5
        if (nums[4]==14&&nums[0]==2&&nums[1]==3&&nums[2]==4&&nums[3]==5){
            return true;
        }
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[i - 1] + 1) {
                return false;
            }
        }
        return true;
    }

    //是否是三条
    private static boolean isSanTiao(int[] nums, char[] colors) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        boolean a = false;
        int count = 0;
        for (Integer i : map.keySet()) {
            //一个出现三次，一个出现两次；即满足条件，花色不影响。
            if (map.get(i) == 3) {
                a = !a;
            }
            if (map.get(i) == 1) {
                count++;
            }
        }
        return a && count == 2;
    }


}
